//void, Obj owner
Unit this;

this = owner.AsUnit;

if (!.IsValid) return;

	Sleep(2000);        

if (.IsValid){
	if(!.IsHeirOf("Hero")) {
		Unit u;

		if(.race==Gaul){
			Sleep(rand(100)+100);
			u = Place(GetRandomHeroClass("GaulHero", .player), .posRH, .player);    
		
		} else if(.race==RepublicanRome){
			Sleep(rand(100)+100);
			if(rand(100) < 50)
				u = Place(GetRandomHeroClass("RepublicanRomanHero", .player), .posRH, .player);    
			else
				u = Place(GetRandomHeroClass("ImperialRomanHero", .player), .posRH, .player);
				
		} else if(.race==Carthage){
			Sleep(rand(100)+100);
			u = Place(GetRandomHeroClass("CarthaginianHero", .player), .posRH, .player);    
		
		} else if(.race==Iberia){
			Sleep(rand(100)+100);
			u = Place(GetRandomHeroClass("IberianHero", .player), .posRH, .player);    
			
		} else if(.race==ImperialRome){
			Sleep(rand(100)+100);
			if(rand(100) < 50)
				u = Place(GetRandomHeroClass("RepublicanRomanHero", .player), .posRH, .player);    
			else
				u = Place(GetRandomHeroClass("ImperialRomanHero", .player), .posRH, .player);
		
		} else if(.race==Britain){
			Sleep(rand(100)+100);
			u = Place(GetRandomHeroClass("BritonHero", .player), .posRH, .player);    
		
		} else if(.race==Egypt){
			Sleep(rand(100)+100);
			u = Place(GetRandomHeroClass("EgyptianHero", .player), .posRH, .player);    
		
		} else if(.race==Germany){
			Sleep(rand(100)+100);
			u = Place(GetRandomHeroClass("GermanHero", .player), .posRH, .player);    
		}
		
		if(u.IsValid){
	   
			if(.level > 30)
				u.AsUnit.SetLevel(30);
			else
				u.AsUnit.SetLevel(.level);
			
			SwapSelectedObj(owner.AsUnit, u);
							
			//PlaySound("data/Sound Entities/PROMOTIONONHERO.XML");
			UserNotification("Promotion on Hero", "", u.pos, u.player);       
			//pr("Player "+.player+" Warrior be promoted on Hero !!!");
			
			.Erase();
			Sleep(3000);
			if(u.IsValid){
				ObjList olb;
				
				u.AsHero.AddItem("Promotion on Hero");
				olb = ClassPlayerObjs("BaseTownhall", u.AsHero.player).GetObjList();
				if(olb.count > 0){        
					u.SetCommand("enter", olb[0].AsBuilding.settlement.GetCentralBuilding);
				}
					
			}
			return;
		}
	}
}
return; 
